package com.huazai.rabbitmq.config.exchange;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 * @author huazai
 * @date 2024/11/11
 */
@Configuration
public class RabbitDirectConfig {

    public static final String DIRECT_QUEUE_ONE = "directQueue-One";
    public static final String DIRECT_QUEUE_TWO = "directQueue-Two";
    public static final String MQ_EXCHANGE_ONE = "MqSendService-One";
    public static final String ROUTING_KEY_ONE = "One";
    public static final String ROUTING_KEY_TWO = "Two";

    @Bean
    public Queue directQueue(){
        //参数介绍
        //1.队列名 2.是否持久化 3.是否独占 4.自动删除 5.其他参数
        return new Queue(DIRECT_QUEUE_ONE,false,false,false,null);
    }

    @Bean
    public Queue directQueue2(){
        //参数介绍
        //1.队列名 2.是否持久化 3.是否独占 4.自动删除 5.其他参数
        return new Queue(DIRECT_QUEUE_TWO,false,false,false,null);
    }

    @Bean
    public DirectExchange directExchange(){
        //参数介绍
        //1.交换器名 2.是否持久化 3.自动删除 4.其他参数
        return new DirectExchange(MQ_EXCHANGE_ONE,false,false,null);
    }

    @Bean
    public Binding directBingExchange(){
        return BindingBuilder.bind(directQueue())   //绑定队列
                .to(directExchange())       //队列绑定到哪个交换器
                .with(ROUTING_KEY_ONE);         //绑定路由key,必须指定
    }

    @Bean
    public Binding directExchange2(){
        return BindingBuilder.bind(directQueue2())   //绑定队列
                .to(directExchange())       //队列绑定到哪个交换器
                .with(ROUTING_KEY_TWO);         //绑定路由key,必须指定
    }
}

